<%@ Control Language="C#" ClassName="DatePicker" %>

<script runat="server">
    private bool ctlEnabled = true;
    private string scriptStr;
    
    private void Page_Load(object sender, System.EventArgs e)
    {
        // Put user code to initialize the page here
        scriptStr = "javascript:return popUpCalendar(this," + getClientID() + @", 'dd-mm-yyyy', '__doPostBack(\'" + getClientID() + @"\')')";
        imgCalendar.Attributes.Add("onclick", scriptStr);
        enabled(ctlEnabled);        
    }    

    // Get the id of the control rendered on client side
    // Very essential for Javascript Calendar scripts to locate the textbox
    public string getClientID()
    {
        return txt_Date.ClientID;
    }

    // This propery sets/gets the calendar date
    public string CalendarDate
    {
        get
        {
            return txt_Date.Text;
        }
        set
        {
            txt_Date.Text = value;
        }
    }
    
    // This property sets/gets the enabled state
    public bool Enabled
    {
        get
        {
            return ctlEnabled;
        }
        set
        {
            ctlEnabled = value;
            enabled(value);
        }
    }
    // function to set control state
    private void enabled(bool state)
    {
        //txt_Date.Enabled = state;
        // readOnly property is vice versa Enabled property
        txt_Date.ReadOnly = !state;        
        if (state)
        {
            txt_Date.CssClass = "";
            imgCalendar.ImageUrl = "cal/calendar.gif";            
            if (imgCalendar.Attributes["onclick"] == null)    
                imgCalendar.Attributes.Add("onclick", scriptStr);
            
        }
        else
        {
            txt_Date.CssClass = "diabled";
            imgCalendar.ImageUrl = "cal/calendar_dis.gif";     
            if (imgCalendar.Attributes["onclick"] != null)                            
                imgCalendar.Attributes.Remove("onclick");
            
        }
    }

</script>

<span>
	<asp:TextBox Columns="15" id="txt_Date" runat="server" />
	<asp:Image ImageAlign="AbsMiddle" id="imgCalendar" runat="server" ImageUrl="cal/calendar.gif" />
</span>
